/**
 * 
 */
package org.swing.utility.system.thread;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lqnhu
 *
 */
public class ThreadLocalMap {
	private static ThreadLocal<Map<String, Object>> tLocal = new ThreadLocal<Map<String, Object>>();

	public static void put(String key, Object value) {
		Map<String, Object> map = (Map<String, Object>) tLocal.get();
		if (map == null) {
			map = new HashMap<String, Object>();
		}
		map.put(key, value);
		tLocal.set(map);
	}

	public static void clearAll() {
		Map<String, Object> map = (Map<String, Object>) tLocal.get();
		if (map != null) {
			map.clear();
		}
		tLocal.set(new HashMap<String, Object>());
	}

	public static Object get(String key) {
		Map<String, Object> map = (Map<String, Object>) tLocal.get();
		if (map == null)
			return null;
		return map.get(key);
	}
}
